#include "CSalesman.h"
#include <iostream>
#include <vector>
#include <ctime>

using namespace std;

int N, M, r1, r2;

const double dPi = 6.2831;

vector< Vertex > GetRandGraf()
{
	vector< Vertex > graf( N * M );

	srand( time( NULL ) );

    vector< Vertex > centers( N );

    for( int i = 0; i < N; ++i )
	{
        double d1 = 1.0 - ( double )( rand() ) / ( RAND_MAX + 1 );
        double _cos = cos( dPi * d1 );
        double _log = log( d1 );

        centers[i].x = r1 * _cos * sqrt( -2 * _log );
        centers[i].y = r2 * sqrt( 1.0 - _cos * _cos ) * sqrt( -2 * _log );
    }
    for( int i = 0; i < N; ++i )
	{
        for( int j = 0; j < M; ++j )
		{
            double d2 = 1.0 - ( double )( rand() ) / ( RAND_MAX + 1 );
            double _cos = cos( dPi * d2 );
            double _log = log( d2 );

            graf[i * M + j].x = r2 * _cos * sqrt( -2 * _log ) + centers[i].x;
            graf[i * M + j].y = r2 * sqrt( 1 - _cos * _cos ) * sqrt( -2 * _log ) + centers[i].y;
        }
    }
	return graf;
}

int main()
{

	cout << "Enter number of centers: ";
	cin >> N;

	cout << "Enter number of points per center: ";
	cin >> M;

	cout << "Enter ranges of spread (2 ranges): ";
	cin >> r1;
	cin >> r2;

    vector< Vertex > graph = GetRandGraf();
	CSalesman a;
	vector< Vertex* > way;
    cout << "Salesman had to go " << a.Salesman( graph, way ) << " kilometers\n";
    return 0;
}